dyn_string dsSysName = makeDynString("System1:");

main()
{
  while (1)
  {
    //loop();
    float value = 22.5 + (float)rand() / 32767.0 ;

    dpSet("AO_SIM.", value);
    delay(0, 100);
  }
}

loop()
{

  for (int i = 1; i <= dynlen(dsSysName); i++)
  {
    if (!dpExists(dsSysName[i] + "_Event.Heartbeat")) continue;

    startThread("makeOnChangeSubsystem", dsSysName[i]);
  }

}

void makeOnChangeSubsystem(string sysName)
{
  string sql;
  sql = "SELECT '_original.._value' FROM '**.STATE.**' "
        "REMOTE '" + sysName  + "' "
        "WHERE _LEAF " ;
  dyn_dyn_anytype ddaTab;

  dpQuery(sql, ddaTab);

  int iLen = dynlen(ddaTab);

  for (int i = 2; i <= iLen; i++)
  {

    string dpe = ddaTab[i][1];

    if (dpElementType(dpe) == DPEL_FLOAT)
    {

      float value = 22.5 + (float)rand() / 32767.0 ;
      dpSet(dpe, value);
      delay(0, 1);
    }
  }

}

